package com.itheima.config;

import com.itheima.interceptor.LoginCheckInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 定义一个拦截器配置类，用来注册拦截器
@Configuration  // @Configuration声明当前类是一个配置类，底层就是@Component，所以在Spring程序启动时会将当前类的对象交给IOC容器
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/**")  // /**表示拦截所有路径
                .excludePathPatterns("/login"); // 排除/login登录请求，不拦截
    }
}
